package DButil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
	private  static String classname="oracle.jdbc.driver.OracleDriver";
	private  static String url="jdbc:oracle:thin:@localhost:1521:orcl";
	private  static String user="testdb";
	private  static String password="testdb";
	
	static {
		try {
			Class.forName(classname);
		} catch (ClassNotFoundException e) {
			System.out.println("class not found,error message is:"+e.getMessage());
		}
	}
	
	
	public static Connection getConnection() {
		Connection connection =null;
		try {
			connection = DriverManager.getConnection(url, user, password);
			//System.out.println("datebase connetion succes");
		} catch (SQLException e) {
			System.out.println("datebase not connection succes,error message is:"+e.getMessage());
		}
		return connection;
	}
	
	public static void closeConnection(Connection connection) {
		if(connection!=null) {
			try {
				connection.close();
				//System.out.println("datebase close susses");
			} catch (SQLException e) {
				System.out.println("database not close succes,error message is:"+e.getMessage());
			}
		}
	}
	
}
